import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class L438_3 {

    public static void main(String[] args) {
//        String s = "cbaebabacd";
        String s = "baa";
//        String p = "abc";
        String p = "aa";
        List<Integer> anagrams = new Solution().findAnagrams(s, p);
        System.out.println(anagrams.toString());

    }

    static class Solution {
        public List<Integer> findAnagrams(String s, String p) {
            if (s.length() < p.length()) {
                return new ArrayList<>();
            }

            ArrayList<Integer> result = new ArrayList<>();
            int[] sCount = new int[26];
            int[] pCount = new int[26];
            for (int i = 0; i < p.length(); i++) {
                pCount[p.charAt(i) - 'a']++;
                sCount[s.charAt(i) - 'a']++;
            }
            if (Arrays.equals(pCount, sCount)) {
                result.add(0);
            }

            for (int i = 0; i < s.length() - p.length(); i++) {
                sCount[s.charAt(i) - 'a']--;
                sCount[s.charAt(i + p.length()) - 'a']++;

                if (Arrays.equals(pCount, sCount)) {
                    result.add(i + 1);
                }
            }

            return result;
        }
    }

}
